package com.hyj.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hyj.service.StudentService;
import com.hyj.mapper.StudentsMapper;
import com.hyj.mapper.UsersMapper;
import com.hyj.entity.Fenye;
import com.hyj.entity.Netfollows;
import com.hyj.entity.Students;
import com.hyj.entity.Users;

@Service
public class StudentServiceImp implements StudentService {
	@Autowired
	private StudentsMapper studentmapper;
	@Autowired
	private UsersMapper usersmapper;
	@Autowired
	private Students student;
	@Override
	public Fenye<Students> selectFenyeStu(Fenye<Students> fenye) {
		List<Students> selectAll = studentmapper.selectAll(fenye);
		Integer selectCount = studentmapper.selectCount(fenye);
		fenye.setTotal(selectCount);
		fenye.setRows(selectAll);
		return fenye;
	}

	@Override
	public Integer updateStu(Students student) {
		// TODO Auto-generated method stub
		return studentmapper.updateStu(student);
	}

	@Override
	public Integer addStu(Students student) {
		// TODO Auto-generated method stub
		return studentmapper.addStu(student);
	}

	@Override
	public Fenye<Students> selectOnlineStu(HttpServletRequest request,
			Fenye<Students> fenye) {

		HttpSession session = request.getSession();
		String name = (String) session.getAttribute("name");
		Users u = new Users();
		u.setLoginName(name);
		/* 根据名称查询用户信息 */
		List<Users> selectuser = usersmapper.selectByname(u);
		fenye.setUserId(selectuser.get(0).getId());
		List<Students> selectOnlineStu = studentmapper.selectOnlineStu(fenye);
		Integer total = studentmapper.CountOnlineStu(fenye);
		fenye.setRows(selectOnlineStu);
		fenye.setTotal(total);
		return fenye;
	}

	@Override
	public Integer delStu(Integer id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Fenye<Students> selectMyStu(HttpServletRequest request,
			Fenye<Students> fenye) {

		HttpSession session = request.getSession();
		String name = (String) session.getAttribute("name");
		Users u = new Users();
		u.setLoginName(name);
		/* 根据名称查询用户信息 */
		List<Users> selectuser = usersmapper.selectByname(u);
		fenye.setUserId(selectuser.get(0).getId());
		List<Students> selectMyStu = studentmapper.selectMyStu(fenye);
		Integer total = studentmapper.CountMyStu(fenye);
		fenye.setRows(selectMyStu);
		fenye.setTotal(total);
		return fenye;
	}

	@Override
	public Fenye<Students> selectStuAll() {
		List<Students> stuAllbyunetPusherId = studentmapper.selectStuAll();
		Fenye<Students> fenye = new Fenye<Students>();
		fenye.setRows(stuAllbyunetPusherId);
		return fenye;
	}

	@Override
	public Integer addGenzong(Netfollows netfollows) {
		/*student.setId(id);*/
		Integer upHiuFang = studentmapper.upHiuFang(student);
		
		System.out.println(upHiuFang);
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		String format = sdf.format(date);
		netfollows.setFollowTime(format);
		return studentmapper.addGenzong(netfollows);
	}

	@Override
	public List<Users> selectUser() {
		// TODO Auto-generated method stub
		return studentmapper.selectUser();
	}

	@Override
	public Integer upIsvaild(Students student) {
		// TODO Auto-generated method stub
		return studentmapper.upIsvaild(student);
	}

	@Override
	public Integer addOnlineStu(Students student) {
		// TODO Auto-generated method stub
		return studentmapper.addOnlineStu(student);
	}



	@Override
	public Integer upvaild(Students student) {
		// TODO Auto-generated method stub
		return studentmapper.upvaild(student);
	}

	
	


}
